package com.demo.util;


import java.io.*;
import java.util.*;

// Referenced classes of package com.velcro.base.util:
//            StringHelper

public class PropertiesHelper
{

    private static Properties properties = new Properties();

    public static Properties loadProperty(String file)
    {
        InputStream in;
        in = PropertiesHelper.class.getResourceAsStream(file);
        try
        {
            properties.load(in);
        }
        catch(IOException e)
        {
            System.out.println("load "+file+" failed..........");
            e.printStackTrace();
        }
        if(in != null)
            try
            {
                in.close();
            }
            catch(Exception exception1) { }
        if(in != null)
            try
            {
                in.close();
            }
            catch(Exception exception2) { }
        if(in != null)
            try
            {
                in.close();
            }
            catch(Exception exception3) { }
        return properties;
    }
    public Boolean getPropertyToBoolean(String key, boolean defaultValue) {
        Boolean result = getPropertyToBoolean(key);
        return result != null ? result : defaultValue;
    }
    public Boolean getPropertyToBoolean(String key) {
        checkPropertyLoading();
        String resultStr = properties.getProperty(key);
        Boolean resultBool = null;
        if (resultStr != null) {
            if (resultStr.trim().equalsIgnoreCase("true"))
                resultBool = true;
            else if (resultStr.trim().equalsIgnoreCase("false"))
                resultBool = false;
        }
        return resultBool;
    }
    private void checkPropertyLoading() {
        if (properties == null)
            throw new RuntimeException("You must load properties file by invoking loadPropertyFile(String) method in configConstant(Constants) method before.");
    }
}
